#ifndef _PARTHUS_TRA_UART_H_
#define _PARTHUS_TRA_UART_H_
/*****************************************************************************
 * MODULE NAME:    tra_uart.h
 * PROJECT CODE:   Bluetooth
 * DESCRIPTION:    Generic UART sub-layer (HCI transport)_
 * MAINTAINER:     John Sheehy
 * CREATION DATE:  27 February 2001
 *
 * SOURCE CONTROL: $Id: tra_uart.h,v 1.8 2009/12/23 11:39:43 tianwq Exp $
 *
 * LICENSE:
 *     This source code is copyright (c) 2000-2004 Ceva Inc.
 *     All rights reserved.
 *
 * SOURCE:         
 *
 *****************************************************************************/
#include "sys_types.h"
#include "sys_config.h"

#include "tra_hcit.h"

/*
 * Line control LCR
 */
#define XR7_LCR_8DIV          0x100
#define XR7_LCR_16DIV         0x000

#define XR7_LCR_DLAB          0x80
#define XR7_LCR_SB            0x40
#define XR7_LCR_PAR_MASK      0x30
#define XR7_LCR_PEN           0x08
#define XR7_LCR_STB           0x04
#define XR7_LCR_CHAR_LEN_MASK 0x03

#define XR7_LCR_5BITS         0x0
#define XR7_LCR_6BITS         0x2
#define XR7_LCR_7BITS         0x1
#define XR7_LCR_8BITS         0x3

#define XR7_LCR_1STOP         0x0
#define XR7_LCR_2STOP         0x4

#define XR7_LCR_PODD          0x0
#define XR7_LCR_PEVEN         0x10
#define XR7_LCR_PFORCE1       0x20
#define XR7_LCR_PFORCE0       0x30


#define TRA_UART_AUTORATE       0x01        /* use uart autorate */
#define TRA_UART_LONGWAIT       0x02        /* use convert_time * 8 */
#define TRA_UART_FOCERATE       0x04        /* force to use rate setting in pskey */

#define HCIT_UART_MTK_FLAG_CONVERT_START       0x80
/*
 * Handle HALs that don't define TRA_HCIT_UART_POLLED_TX_SUPPORTED
 */
#ifndef TRA_HCIT_UART_POLLED_TX_SUPPORTED
    #define TRA_HCIT_UART_POLLED_TX_SUPPORTED 0
#endif


/*
 * Structure for UARTs
 */

struct tra_hcit_uart_info
{
    /*
     * Common structure (generic HCI transport structure above)
     * Any accesses to members of the common structure below should
     * collapse into additions from the base of the tra_hcit_uart_info
     * structure. NOTE: The common structure _must_ be the first member of
     * this or any other transport type.
     */

    struct tra_hcit_info common;

    /* Functions to initialise, shutdown, transmit a block and transmit a block polled  */

    void (*initialise)(u_int32 speed, u_int32 uart_setting);
    void (*shutdown)(void);
    void (*restart)(void);
    void (*setautorate)(u_int8 enable);
    void (*setbaudrate)(u_int32 speed);
    void (*transmit)(volatile u_int8 **data,volatile u_int32 *len, u_int8 flag, void (*txcb)(void));
#if TRA_HCIT_UART_POLLED_TX_SUPPORTED == 1
    void (*poll_tx)(volatile u_int8 **data, volatile u_int32 *len, u_int8 flag);
#endif
    void (*setup)(volatile u_int8 *rx_buffer, u_int16 rx_length, u_int8 flag);

    /* Error counters and other information */

    u_int16 framing_errors;
    u_int16 overrun_errors;

	u_int32 baudrate;
	u_int32 newrate;
	u_int16 convert_time;
    u_int16 uart_flags;	
	u_int16 uart_setting;
};


/*
 * Types of UART line status errors
 */

enum
{
    TRA_HCIT_UART_FRAMING_ERROR,
    TRA_HCIT_UART_OVERRUN_ERROR,
    TRA_HCIT_UART_PARITY_ERROR
};

void TRAhcit_UART_Initialise(void);
void TRAhcit_UART_Shutdown(void);
void TRAhcit_UART_Convert_Baudrate(void);
void TRAhcit_UART_Transmit(u_int8 *pdu, u_int32 pdu_len, u_int8 *head, u_int8 head_len, u_int8 tra_source, t_deviceIndex device_index);
void TRAhcit_UART_Rx_Data(u_int16 length);

void TRAhcit_UART_Tx_PDU(void);

boolean TRAhcit_UART_Transport_Activity(void);

__INLINE__ void TRAhcit_UART_Indicate_Error(u_int8 type);


/*
 * Include any inline'd helper methods
 */

#ifdef __USE_INLINES__
#include "tra_uart_impl.h"
#endif

#endif /* _PARTHUS_TRA_UART_H_ */
